#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
struct ListNode
{
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};
class Solution
{
public:
    stack<char> stk;
    queue<char> que;
    bool isPalindrome(ListNode *head)
    {
        ListNode *ptr = head;
        while (ptr != nullptr)
        {
            stk.push(ptr->val);
            que.push(ptr->val);
            ptr = ptr->next;
        }
        while (stk.empty())
        {
            if (stk.top() != que.front())
                return false;
            stk.pop(), que.pop();
        }
        return true;
    }
};